using System.Xml;

namespace RunCamlSample.QueryBuilders
{
    /// <summary>
    /// Create By: Nguyen Thanh Tung
    /// </summary>
    public class QueryOptionsBuilder : BaseQueryBuilder
    {
        readonly XmlDocument document = new XmlDocument();

        private readonly XmlNode queryOptions;
        private bool isAddViewAtrib = false;
        private XmlNode attributes;

        public QueryOptionsBuilder()
        {
            queryOptions = AddXmlElement(document, "QueryOptions", "");
        }

        public QueryOptionsBuilder Scope(Scope scope)
        {
            if (!isAddViewAtrib)
            {
                attributes = AddXmlElement(queryOptions, "ViewAttributes", "");
                isAddViewAtrib = true;
            }

            AddXmlAttribute(attributes, "Scope", scope.ToString());

            return this;
        }

        public QueryOptionsBuilder MandatoryColumns(bool isInclude)
        {
            AddXmlElement(queryOptions, "IncludeMandatoryColumns", isInclude.ToString().ToUpper());

            return this;
        }

        public QueryOptionsBuilder RowLimit(int limit)
        {
            AddXmlElement(queryOptions, "RowLimit", limit.ToString());

            return this;
        }

        public QueryOptionsBuilder Folder(string foldername)
        {
            AddXmlElement(queryOptions, "Folder", foldername);

            return this;
        }

        public XmlNode ToXmlNode()
        {
            return queryOptions;
        }

        public QueryOptionsBuilder DateInUtc(bool isInUtc)
        {
            AddXmlElement(queryOptions, "DateInUtc", isInUtc.ToString().ToUpper());

            return this;
        }
    }
}